package com.bang.rabbitmq.consumer.config;

import com.bang.rabbitmq.consumer.constants.QueueConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: Bang
 * @Date: 2019/11/3 21:13
 * @Description:
 */
@Configuration
public class RabbitMqConfig {


    @Bean
    public TopicExchange topicExchange() {
        TopicExchange build = ExchangeBuilder.topicExchange(QueueConstants.TEST_TOPIC_EXCHANGE).durable(true).build();
        return build;
    }

    @Bean
    public Queue topicHelloQueue() {
        return QueueBuilder.durable(QueueConstants.TEST_TOPIC_QUEUE_HELLO).build();
    }

    @Bean
    public Queue topicWorldQueue() {
        return QueueBuilder.durable(QueueConstants.TEST_TOPIC_QUEUE_WORLD).build();
    }

    @Bean
    public Binding helloBinding() {
        return BindingBuilder.bind(topicHelloQueue()).to(topicExchange()).with(QueueConstants.TEST_TOPIC_ROUTE_KEY);
    }

    @Bean
    public Binding worldBinding() {
        return BindingBuilder.bind(topicWorldQueue()).to(topicExchange()).with(QueueConstants.TEST_TOPIC_ROUTE_KEY);
    }

    @Bean
    public FanoutExchange fanoutExchange() {
        return ExchangeBuilder.fanoutExchange(QueueConstants.FANOUT_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue fanoutQueue1() {
        return QueueBuilder.durable(QueueConstants.FANOUT_QUEUE1).build();
    }
    @Bean
    public Queue fanoutQueue2() {
        return QueueBuilder.durable(QueueConstants.FANOUT_QUEUE2).build();
    }
    @Bean
    public Queue fanoutQueue3() {
        return QueueBuilder.durable(QueueConstants.FANOUT_QUEUE3).build();
    }

    @Bean
    public Binding binding1() {
        return BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange());
    }
    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }
    @Bean
    public Binding binding3() {
        return BindingBuilder.bind(fanoutQueue3()).to(fanoutExchange());
    }
}
